﻿using UnityEngine;

namespace PP.Basic
{
    /// <summary>
    /// 音频播放任务小对象
    /// 记录任务信息，供Audio控制播放
    /// </summary>
    public struct AudioPlayTask
    {
        public object TaskKey;
        public AudioSource AudioSource;

        public bool IsValid => TaskKey != null && (object)AudioSource != null;

        public void Complete()
        {
            Reset();
        }

        public void Cancel()
        {
            if (!IsValid)
                return;

            Audio.Instance.StopAudio(this);
            Reset();
        }

        private void Reset()
        {
            TaskKey = null;
            AudioSource = null;
        }
    }
}
